<template>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="单据编码">
            <el-input v-model="formInline.documentNumber" placeholder="单据编码" clearable />
        </el-form-item>
        <el-form-item label="单据状态">
            <el-select v-model="formInline.documentStatus" placeholder="请选择" clearable style="width: 150px;">
                <el-option :lable="'开立'" value="开立"></el-option>
                <el-option :lable="'审核'" value="审核"></el-option>
                <el-option :lable="'退回'" value="退回"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="业务状态">
            <el-select v-model="formInline.businessStatus" placeholder="请选择" clearable style="width: 150px;">
                <el-option :lable="'正常'" value="正常"></el-option>
                <el-option :lable="'挂起'" value="挂起"></el-option>
                <el-option :lable="'手工关闭'" value="手工关闭"></el-option>
                <el-option :lable="'系统关闭'" value="系统关闭"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="GetSuppliers()">搜索</el-button>
        </el-form-item>

        <table style="width: 30%">
            <tr>
                <td><el-button type="primary" :icon="List" @click="">查询所有</el-button></td>
                <td> <el-upload ref="fileInput" class="upload-demo" action="http://localhost:5020/api/OutOfStock/Handle"
                        :show-file-list="false" :on-success="AddExcelData">
                        <el-button type="primary" :icon="Upload">导入数据</el-button>
                    </el-upload> </td>
                <td> <el-button type="primary" :icon="Upload">导出</el-button></td>
                <td> <el-button type="primary" :icon="Plus" plain
                        @click="router.push('/PurchaseWarehousingAdd')">新增</el-button>
                </td>
                <td>
                    <el-button type="primary" :icon="List"
                        @click="router.push('/PurchaseWarehousingShow')">明细</el-button>
                </td>
            </tr>
        </table>
    </el-form>



    <el-empty description="暂无数据" v-show="suppliers.length == 0" />
    <el-table :data="suppliers" stripe style="width: 100%" v-show="suppliers.length != 0">
        <el-table-column prop="documentNumber" label="单据编码">
            <template #default="scope">
                <el-link type="primary" @click="chakan(scope.row.documentNumber)">{{
                    scope.row.documentNumber }}</el-link>
            </template>
        </el-table-column>
        <el-table-column prop="documentDate" label="单据日期">
            <template #default="scope">
                {{ scope.row.documentDate == null ? "" : scope.row.documentDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="businessType" label="单据类型" />
        <el-table-column prop="warehouseId" label="仓库" />
        <el-table-column prop="businessStatus" label="业务状态" />
        <el-table-column prop="auditDate" label="审核日期">
            <template #default="scope">
                {{ scope.row.auditDate == null ? "" : scope.row.auditDate.substring(0, 10) }}
            </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="140">
            <template #default="scope">
                <el-button link type="primary" size="small"
                    @click="router.push('/SalesOrderEditView?id=' + scope.row.documentNumber)">查看</el-button>
                <el-button link type="danger" size="small" disabled="true">删除</el-button>
                <el-button link type="success" size="small" disabled="true">编辑</el-button>
            </template>
        </el-table-column>
    </el-table>

    <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
import axios from 'axios';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue'
import type { TabsPaneContext, UploadInstance, UploadProps } from 'element-plus'
const cpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const router = useRouter()
const route = useRoute()
const apiurls = import.meta.env.VITE_APP_API_URL_BasicInformationCommon;//5176
const bpiurls = import.meta.env.VITE_APP_API_URL_BasicInformationWrite;//5013
const epiurls = import.meta.env.VITE_APP_API_URL_RBACCommon;//5214
const dpiurls = import.meta.env.VITE_APP_API_URL_RBACWrite;//5268
const fpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementWrite;//5020
onMounted(() => {
    GetSuppliers()
});

const formInline = reactive({
    documentNumber: '',
    businessStatus: '',
    salesOrder: '',
    documentStatus: '',
    materialName: '',
    itemBianma: '',
    pageIndex: 1,
    pageSize: 10,
    pageCount: 0,
    totalCount: 0,

})


const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
//销售订单单据列表
const suppliers: any = ref([]);
const GetSuppliers = () => {
    axios
        .get(apiurls + '/api/PurchaseWarehousing/GetPurchaseWarehousingList',
            {
                params: {
                    documentNumber: formInline.documentNumber,
                    materialName: formInline.materialName,
                    businessStatus: formInline.businessStatus,
                    documentStatus: formInline.documentStatus,
                    salesOrder: formInline.salesOrder,
                    itemBianma: formInline.itemBianma,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.pageCount = res.data.data.pageCount;
            formInline.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};
//导入相关
const AddExcelData: UploadProps['onSuccess'] = (
    response: any

) => {
    if (response != null) {
        ElMessage.success("导入成功");
        GetSuppliers()
    }
    else {
        ElMessage.error("导入失败");
    }
}

// //导出Excel
// const GetOut = () => {
//     axios.get(cpiurls + '/api/OutOfStock/ExportExcel').then((res) => {
//         console.log(res);
//     }).catch((err) => {
//         console.log(err);
//     })
// }

const chakan = (documentNumber: any) => {
    router.push({
        path: '/PurchaseWarehousingSeiadal',
        query: {
            documentNumber: documentNumber
        }
    })
}

const GetSuppliers1 = () => {
    axios
        .get(apiurls + '/api/PurchaseWarehousing/GetPurchaseWarehousingList',
            {
                params: {
                    documentNumber: '',
                    materialName: '',
                    businessStatus: '',
                    documentStatus: '',
                    itemBianma: '',
                    salesOrder: '',
                    pageIndex: 1,
                    pageSize: 10,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.pageCount = res.data.pageCount;
            formInline.totalCount = res.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetSuppliers()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetSuppliers()
}



const formLabelWidth = '140px'

</script>

<style>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
</style>